package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;


/**
 * @ClassName UserMapper
 * @Description C端-用户持久层
 * @Author sld
 * @Date 2024/7/10 16:47
 * Version 1.0
 **/



@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select id,openid,`name`,phone,sex,id_number,avatar,create_time " +
            "   from `user` where openid = #{openid}")
    User getByOpenid(String openid);

    /**
     * 新增用户
     * @param user
     */
    @Insert("insert into user(openid,`name`,phone,sex,id_number,avatar,create_time)" +
            "  values(#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")    // 这样新增并不能返回自增的主键
    @Options(useGeneratedKeys = true,keyProperty = "id")  // 加上这个注解，新增操作就能返回主键id
    void insert(User user);
}
